package tec.stan.ling.topo.graph.figure;

import org.eclipse.draw2d.Figure;
import org.eclipse.draw2d.StackLayout;
import org.eclipse.draw2d.text.FlowPage;
import org.eclipse.draw2d.text.ParagraphTextLayout;
import org.eclipse.draw2d.text.TextFlow;
import org.eclipse.swt.graphics.Color;
import org.eclipse.swt.graphics.Font;

/**
 * Text figure for node name and link name.
 * 
 * @author Stan 张新潮
 * @since 2010-01-04
 */
public class TextFigure extends Figure {

	public TextFlow contents;

	public TextFigure(String text) {
		FlowPage flowPage = new FlowPage();

		contents = new TextFlow();
		ParagraphTextLayout layout = new ParagraphTextLayout(contents,
				ParagraphTextLayout.WORD_WRAP_SOFT);
		contents.setLayoutManager(layout);
		contents.setText(text);
		flowPage.add(contents);

		StackLayout slaytout = new StackLayout();

		setLayoutManager(slaytout);
		add(flowPage);
		setOpaque(false);
	}

	public void setText(String text) {
		contents.setText(text);
	}

	public String getText() {
		return contents.getText();
	}

	public void setFont(Font f) {
		super.setFont(f);
		contents.setFont(f);
	}

	public void setForegroundColor(Color color) {
		super.setForegroundColor(color);
		contents.setForegroundColor(color);
	}
}
